<?php

namespace App\Http\Controllers\Backend;

use App\Http\Repositories\UserRepository;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class Usercontroller extends Controller
{
    protected $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    /**
     * 用户列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request)
    {
        return responseResult($this->userRepository->getList($request->all()), self::SUCCESS_CODE);
    }

    /**
     * 修改用户状态
     * @param $id
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function changeEnable($id, Request $request)
    {
        $this->validate($request, ['status' => 'required']);
        $result = $this->userRepository->changeEnable($id, $request->get("status"));
        return responseResult([], $result ? self::SUCCESS_CODE : self::ERROR_CODE);
    }



}
